package com.right.dao.impl;

import java.util.List;

import com.Tools.DBTools;
import com.Tools.PageData;
import com.right.dao.CommentDao;
import com.right.entity.Comment;


 public class CommentDaoImp implements CommentDao {
/**
 * 增加评论的方法
 */
	@Override
	public boolean addcomment(Comment comment) {
	if (comment!=null) {
		String sql="insert into comment values(null,?,?,?,now())";
		           int n=DBTools.exUpdate(sql,comment.getOrderid(),comment.getJudge(),comment.getContent());
		        	
		           return n>0;
	}
		return false;
	}
/**
 * 删除评论的方法
 */
	@Override
	public boolean delcomment(int commentid) {
		String sql="delete from comment  where commentid =?";
		int n =DBTools.exUpdate(sql, commentid);
		return n>0;
	}
/**
 * 修改评论的方法
 */
	@Override
	public boolean updatecomment(Comment comment) {
	if (comment!=null) {
		String sql="update comment set orderid=?,judge=?,content=?,commenttime=? where commentid=?";
		      int n=DBTools.exUpdate(sql,comment.getOrderid(),comment.getJudge(),comment.getContent(),
		      comment.getCommenttime(),comment.getCommentid());
		      return n>0;
		          
	}
		return false;
	}
/**
 * 模糊查询评论的方法
 */
	@Override
	public List<Comment> getComments(String keywords) {
		String sql="select*from comment where orderid like ?";  
		return (List<Comment>) DBTools.exQuery(sql, Comment.class,'%' +  keywords + "%");
	}
	
	/**
	 * 分页查询评论的方法
	 */
@Override
public PageData<Comment> getCommentByPage(int page, int pageSize, String keywords) {
	String sql = "select * from comment where orderid like ?";
	PageData<Comment> pd= DBTools.exQueryByPage(sql, Comment.class, page, pageSize, '%' +  keywords + "%");
	return pd;
}

}
